﻿using System;
using System.Threading;

namespace csharpbiancheng_ch14_thread_mutex_exampel
{
    class Program
    {
        private static Mutex mutex = new Mutex();
        public static void PakingSpace(object num)
        {
            if (mutex.WaitOne())
            {
                try
                {
                    Console.WriteLine("车牌号{0}的车驶入",num);
                    Thread.Sleep(1000);
                }
                finally
                {
                    Console.WriteLine("车牌号{0}的车离开", num);
                    mutex.ReleaseMutex();
                }

            }
        }
        static void Main(string[] args)
        {
            ParameterizedThreadStart ts = new ParameterizedThreadStart(PakingSpace);
            Thread t1 = new Thread(ts);
            t1.Start("晋A123456");
            Thread t2 = new Thread(ts);
            t2.Start("晋A654321");
        }
    }
}
